import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import Layout from '../views/layout.vue';

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/home',
  },
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('../views/home/index.vue'),
      },
      {
        path: '/task',
        name: 'task',
        children: [
          {
            path: 'business',
            name: 'business',
            component: () => import('../views/task/business.vue')
          },
          {
            path: 'operation',
            name: 'operation',
            component: () => import('../views/task/operation.vue')
          }
        ]
      },
      {
        path: '/node',
        name: 'Node',
        children: [
          {
            path: 'region',
            name: 'region',
            component: () => import('../views/node/region.vue')
          },
          {
            path: 'node',
            name: 'node',
            component: () => import('../views/node/node.vue')
          },
          {
            path: 'partner',
            name: 'partner',
            component: () => import('../views/node/partner.vue')
          }
        ]
      },
      {
        path: '/vm',
        name: 'vm',
        children: [
          {
            path: 'index',
            name: 'vmIndex',
            component: () => import('../views/vm/index.vue')
          },
          {
            path: 'status',
            name: 'status',
            component: () => import('../views/vm/status.vue')
          },
          {
            path: 'type',
            name: 'type',
            component: () => import('../views/vm/type.vue')
          }
        ]
      },
      {
        path: '/user',
        name: 'user',
        children: [
          {
            path: 'index',
            name: 'userIndex',
            component: () => import('../views/user/index.vue')
          },
          {
            path: 'user-task-stats',
            name: 'user-task-stats',
            component: () => import('../views/user/user-task-stats.vue')
          },
          {
            path: 'user-work',
            name: 'user-work',
            component: () => import('../views/user/user-work.vue')
          }
        ]
      },
      {
        path: '/sku',
        name: 'Sku',
        children: [
          {
            path: 'sku-class',
            name: 'sku-class',
            component: () => import('../views/sku/sku-class.vue')
          },
          {
            path: 'sku',
            name: 'sku',
            component: () => import('../views/sku/sku.vue')
          }
        ]
      },
      {
        path: '/policy/index',
        name: 'policy',
        component: () => import('../views/policy/index.vue'),
      },
      {
        path: '/order/index',
        name: 'order',
        component: () => import('../views/order/index.vue'),
      },
      {
        path: '/report/index',
        name: 'report',
        component: () => import('../views/report/index.vue'),
      },
    ],
  },
  {
    path: '/login',
    name: 'Login',
    meta: {
      title: '登录',
    },
    component: () => import(/* webpackChunkName: "login" */ '../views/login.vue'),
  }
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

// router.beforeEach((to, from, next) => {
//     document.title = '帝可得后台';
//     const role = localStorage.getItem('ms_username');
//     if (!role && to.path !== '/login') {
//         return next('/login');
//     }
//     next();
// });

export default router;
